//
//  ByUIClassificationVC.m
//  itboye_shop_ios
//
//  Created by pro on 17/2/7.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUIClassificationVC.h"

// vc
#import "ByUIProductDetailVC.h"             // 详情页

// view
#import "ByViewClassificationScroll.h"      // 分类滑动视图
#import "ByViewSubClassificationScroll.h"   // 子分类滑动视图

@interface ByUIClassificationVC ()

@property (nonatomic, strong) ByViewClassificationScroll    *classScroll;
@property (nonatomic, strong) ByViewSubClassificationScroll *subClassScroll;

@end

@implementation ByUIClassificationVC

#pragma mark - 视图方法
- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"分类";
    
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

    [self addBYItemviews:@[@"详情页测试"] mode:ByNavigationItemModeText position:ByNavigationItemPositionModeRight];
    
    // 设置点击回调
    [self setScrollClickBlock];

}

#pragma mark - 懒加载
- (ByViewClassificationScroll *)classScroll {
    
    if (!_classScroll) {
        _classScroll = [[ByViewClassificationScroll alloc] initWithFrame:CGRectMake(0, 0, 80, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
        NSMutableArray *temp = [[NSMutableArray alloc] init];
        for (int i = 0; i < 20; i ++) {
            ByModelClassification *model = [[ByModelClassification alloc] init];
            model.name = [NSString stringWithFormat:@"分类%i", i + 1];
            [temp addObject:model];
        }
        _classScroll.classModels = temp.copy;
        [self.view addSubview:_classScroll];
    }
    return _classScroll;
}
- (ByViewSubClassificationScroll *)subClassScroll {
    
    if (!_subClassScroll) {
        _subClassScroll = [[ByViewSubClassificationScroll alloc] initWithFrame:CGRectMake(80 + 10, 0, SCREEN_WIDTH - (80 + 20), SCREEN_HEIGHT - 64 - 49)];
        NSMutableArray *temp = [[NSMutableArray alloc] init];
        for (int i = 0; i < 5; i ++) {
            
            ByModelSubClassification *model = [[ByModelSubClassification alloc] init];
            model.name = [NSString stringWithFormat:@"子分类%i", i + 1];
            NSMutableArray *subTemp = [[NSMutableArray alloc] init];
            int randomMax = arc4random_uniform(10) + 5;
            for (int j = 0; j < randomMax; j ++) {
                ByModelSubClassification *subModel = [[ByModelSubClassification alloc] init];
                subModel.name = [NSString stringWithFormat:@"三级分类%i", j + 1];
                [subTemp addObject:subModel];
            }
            model.subClasses = subTemp.copy;
            [temp addObject:model];
        }
        _subClassScroll.level2Models = temp.copy;
        [self.view addSubview:_subClassScroll];
    }
    return _subClassScroll;
}

#pragma mark - 设置点击回调
- (void)setScrollClickBlock {
    
    __weak typeof(self) weakself = self;
    
    [self.classScroll setSelectBlock:^(ByModelClassification *model) {
        
        [weakself.subClassScroll reloadData];
        weakself.subClassScroll.contentOffset = CGPointZero;
    }];
    
    
}



#pragma mark - 点击事件
- (void)rightItemsAction:(NSInteger)rightIndex {
    
    ByUIProductDetailVC *vc = [[ByUIProductDetailVC alloc] init];
    [self by_normalPush:vc hasNavi:YES];
}


@end
